{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 编制音乐索引\n",
    "\n",
    "捕捉音乐风格，建立索引，实现音乐的搜索引擎，就可以用来听歌识曲了，类似于 Shazam。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [],
   "source": [
    "import random\n",
    "random.seed(42)\n",
    "\n",
    "import numpy as np\n",
    "np.random.seed(42)\n",
    "\n",
    "import tensorflow as tf\n",
    "tf.random.set_seed(42)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "这里做了个简单的数据集，包含我随便选的 131 首歌："
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "  类型（A专辑M合集）   曲目数量                                        名称          艺人  \\\n0          A     17                                   Revival      Eminem   \n1          A     12                                        死灰      邪恶少年EB   \n2          A      8                             One Last Kiss        宇多田光   \n3          M     22                                  国语老歌随机合集           -   \n4          M     16                                   欧美怀旧盗版碟           -   \n5          A     14                                      奇跡の山        岸部真明   \n6          A     21   VIOLET EVERGARDEN：Automemories - Disc 1   Evan Call   \n7          M      9                                 世纪乐典-古琴名曲           -   \n8          M     12                                   古典乐随机合集           -   \n\n     语种                                       风格(选取理由)  \n0    英语     Hip-Hop (转型之作，有大量流行等现代元素 删了两首太短的Interlude)  \n1    中文                    Hip-Hop（OldSchool 删了 Intro）  \n2    日语   Pop (有多个版本Beautiful World 另有两首有Instrumental)  \n3    中文                                        流行 & 摇滚  \n4    英文                                        流行 & 摇滚  \n5   纯音乐                                             指弹  \n6   纯音乐                                             原声  \n7   纯音乐                                           中国古代  \n8   纯音乐                                             古典  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>类型（A专辑M合集）</th>\n      <th>曲目数量</th>\n      <th>名称</th>\n      <th>艺人</th>\n      <th>语种</th>\n      <th>风格(选取理由)</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>A</td>\n      <td>17</td>\n      <td>Revival</td>\n      <td>Eminem</td>\n      <td>英语</td>\n      <td>Hip-Hop (转型之作，有大量流行等现代元素 删了两首太短的Interlude)</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>A</td>\n      <td>12</td>\n      <td>死灰</td>\n      <td>邪恶少年EB</td>\n      <td>中文</td>\n      <td>Hip-Hop（OldSchool 删了 Intro）</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>A</td>\n      <td>8</td>\n      <td>One Last Kiss</td>\n      <td>宇多田光</td>\n      <td>日语</td>\n      <td>Pop (有多个版本Beautiful World 另有两首有Instrumental)</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>M</td>\n      <td>22</td>\n      <td>国语老歌随机合集</td>\n      <td>-</td>\n      <td>中文</td>\n      <td>流行 &amp; 摇滚</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>M</td>\n      <td>16</td>\n      <td>欧美怀旧盗版碟</td>\n      <td>-</td>\n      <td>英文</td>\n      <td>流行 &amp; 摇滚</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>A</td>\n      <td>14</td>\n      <td>奇跡の山</td>\n      <td>岸部真明</td>\n      <td>纯音乐</td>\n      <td>指弹</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>A</td>\n      <td>21</td>\n      <td>VIOLET EVERGARDEN：Automemories - Disc 1</td>\n      <td>Evan Call</td>\n      <td>纯音乐</td>\n      <td>原声</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>M</td>\n      <td>9</td>\n      <td>世纪乐典-古琴名曲</td>\n      <td>-</td>\n      <td>纯音乐</td>\n      <td>中国古代</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>M</td>\n      <td>12</td>\n      <td>古典乐随机合集</td>\n      <td>-</td>\n      <td>纯音乐</td>\n      <td>古典</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DIR = \"/Volumes/shared/murecom/intro/idx-local-mp3/\"\n",
    "\n",
    "def myfile(name):\n",
    "    return os.path.join(DIR, name)\n",
    "\n",
    "\n",
    "import os\n",
    "import pandas\n",
    "\n",
    "pandas.read_csv(myfile(\"songs.csv\"))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "把音乐提取出来："
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "131"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MUSIC_ROOT = myfile(\"mp3s\")\n",
    "\n",
    "mp3s = []\n",
    "for root, subdirs, files in os.walk(MUSIC_ROOT):\n",
    "    for fn in files:\n",
    "        if fn.endswith('.mp3'):\n",
    "            mp3s.append(os.path.join(root, fn))\n",
    "len(mp3s)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "处理 MP3 文件，获取梅尔频谱图"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "  0%|          | 0/131 [00:00<?, ?it/s]\u001B[A\u001B[A\n",
      "\n",
      "  1%|          | 1/131 [00:00<01:48,  1.20it/s]\u001B[A\u001B[A\n",
      "\n",
      "  2%|▏         | 2/131 [00:01<01:25,  1.51it/s]\u001B[A\u001B[A\n",
      "\n",
      "  2%|▏         | 3/131 [00:01<01:19,  1.62it/s]\u001B[A\u001B[A\n",
      "\n",
      "  3%|▎         | 4/131 [00:02<01:14,  1.70it/s]\u001B[A\u001B[A\n",
      "\n",
      "  4%|▍         | 5/131 [00:03<01:13,  1.71it/s]\u001B[A\u001B[A\n",
      "\n",
      "  5%|▍         | 6/131 [00:03<01:15,  1.66it/s]\u001B[A\u001B[A\n",
      "\n",
      "  5%|▌         | 7/131 [00:04<01:11,  1.74it/s]\u001B[A\u001B[A\n",
      "\n",
      "  6%|▌         | 8/131 [00:04<01:08,  1.79it/s]\u001B[A\u001B[A\n",
      "\n",
      "  7%|▋         | 9/131 [00:05<01:06,  1.83it/s]\u001B[A\u001B[A\n",
      "\n",
      "  8%|▊         | 10/131 [00:05<01:05,  1.85it/s]\u001B[A\u001B[A\n",
      "\n",
      "  8%|▊         | 11/131 [00:06<01:04,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      "  9%|▉         | 12/131 [00:06<01:03,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 10%|▉         | 13/131 [00:07<01:02,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 11%|█         | 14/131 [00:07<01:02,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 11%|█▏        | 15/131 [00:08<01:01,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 12%|█▏        | 16/131 [00:08<01:01,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 13%|█▎        | 17/131 [00:09<01:01,  1.84it/s]\u001B[A\u001B[A\n",
      "\n",
      " 14%|█▎        | 18/131 [00:10<01:02,  1.81it/s]\u001B[A\u001B[A\n",
      "\n",
      " 15%|█▍        | 19/131 [00:10<01:00,  1.85it/s]\u001B[A\u001B[A\n",
      "\n",
      " 15%|█▌        | 20/131 [00:11<00:59,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 16%|█▌        | 21/131 [00:11<00:57,  1.91it/s]\u001B[A\u001B[A\n",
      "\n",
      " 17%|█▋        | 22/131 [00:12<00:57,  1.91it/s]\u001B[A\u001B[A\n",
      "\n",
      " 18%|█▊        | 23/131 [00:12<00:56,  1.91it/s]\u001B[A\u001B[A\n",
      "\n",
      " 18%|█▊        | 24/131 [00:13<00:57,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 19%|█▉        | 25/131 [00:13<00:56,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 20%|█▉        | 26/131 [00:14<00:55,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 21%|██        | 27/131 [00:14<00:55,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 21%|██▏       | 28/131 [00:15<00:54,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 22%|██▏       | 29/131 [00:15<00:54,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 23%|██▎       | 30/131 [00:16<00:53,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 24%|██▎       | 31/131 [00:16<00:53,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 24%|██▍       | 32/131 [00:17<00:53,  1.85it/s]\u001B[A\u001B[A\n",
      "\n",
      " 25%|██▌       | 33/131 [00:18<00:52,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 26%|██▌       | 34/131 [00:18<00:52,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 27%|██▋       | 35/131 [00:19<00:52,  1.83it/s]\u001B[A\u001B[A\n",
      "\n",
      " 27%|██▋       | 36/131 [00:19<00:51,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 28%|██▊       | 37/131 [00:20<00:49,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 29%|██▉       | 38/131 [00:20<00:48,  1.92it/s]\u001B[A\u001B[A\n",
      "\n",
      " 30%|██▉       | 39/131 [00:21<00:48,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 31%|███       | 40/131 [00:21<00:47,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 31%|███▏      | 41/131 [00:22<00:47,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 32%|███▏      | 42/131 [00:22<00:47,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 33%|███▎      | 43/131 [00:23<00:47,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 34%|███▎      | 44/131 [00:23<00:47,  1.82it/s]\u001B[A\u001B[A\n",
      "\n",
      " 34%|███▍      | 45/131 [00:24<00:47,  1.81it/s]\u001B[A\u001B[A\n",
      "\n",
      " 35%|███▌      | 46/131 [00:25<00:46,  1.82it/s]\u001B[A\u001B[A\n",
      "\n",
      " 36%|███▌      | 47/131 [00:25<00:45,  1.84it/s]\u001B[A\u001B[A\n",
      "\n",
      " 37%|███▋      | 48/131 [00:26<00:44,  1.85it/s]\u001B[A\u001B[A\n",
      "\n",
      " 37%|███▋      | 49/131 [00:26<00:44,  1.84it/s]\u001B[A\u001B[A\n",
      "\n",
      " 38%|███▊      | 50/131 [00:27<00:43,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 39%|███▉      | 51/131 [00:27<00:42,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 40%|███▉      | 52/131 [00:28<00:41,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 40%|████      | 53/131 [00:28<00:41,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 41%|████      | 54/131 [00:29<00:40,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 42%|████▏     | 55/131 [00:29<00:40,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 43%|████▎     | 56/131 [00:30<00:39,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 44%|████▎     | 57/131 [00:30<00:39,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 44%|████▍     | 58/131 [00:31<00:38,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 45%|████▌     | 59/131 [00:31<00:38,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 46%|████▌     | 60/131 [00:32<00:37,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 47%|████▋     | 61/131 [00:32<00:37,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 47%|████▋     | 62/131 [00:33<00:36,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 48%|████▊     | 63/131 [00:34<00:35,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 49%|████▉     | 64/131 [00:34<00:35,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 50%|████▉     | 65/131 [00:35<00:35,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 50%|█████     | 66/131 [00:35<00:34,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 51%|█████     | 67/131 [00:36<00:34,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 52%|█████▏    | 68/131 [00:36<00:33,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 53%|█████▎    | 69/131 [00:37<00:33,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 53%|█████▎    | 70/131 [00:37<00:32,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 54%|█████▍    | 71/131 [00:38<00:31,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 55%|█████▍    | 72/131 [00:38<00:31,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 56%|█████▌    | 73/131 [00:39<00:31,  1.83it/s]\u001B[A\u001B[A\n",
      "\n",
      " 56%|█████▋    | 74/131 [00:39<00:30,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 57%|█████▋    | 75/131 [00:40<00:29,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 58%|█████▊    | 76/131 [00:40<00:29,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 59%|█████▉    | 77/131 [00:41<00:28,  1.91it/s]\u001B[A\u001B[A\n",
      "\n",
      " 60%|█████▉    | 78/131 [00:41<00:27,  1.94it/s]\u001B[A\u001B[A\n",
      "\n",
      " 60%|██████    | 79/131 [00:42<00:27,  1.92it/s]\u001B[A\u001B[A\n",
      "\n",
      " 61%|██████    | 80/131 [00:43<00:27,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 62%|██████▏   | 81/131 [00:43<00:26,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 63%|██████▎   | 82/131 [00:44<00:26,  1.85it/s]\u001B[A\u001B[A\n",
      "\n",
      " 63%|██████▎   | 83/131 [00:44<00:25,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 64%|██████▍   | 84/131 [00:45<00:24,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 65%|██████▍   | 85/131 [00:45<00:24,  1.92it/s]\u001B[A\u001B[A\n",
      "\n",
      " 66%|██████▌   | 86/131 [00:46<00:23,  1.93it/s]\u001B[A\u001B[A\n",
      "\n",
      " 66%|██████▋   | 87/131 [00:46<00:22,  1.93it/s]\u001B[A\u001B[A\n",
      "\n",
      " 67%|██████▋   | 88/131 [00:47<00:22,  1.92it/s]\u001B[A\u001B[A\n",
      "\n",
      " 68%|██████▊   | 89/131 [00:47<00:21,  1.91it/s]\u001B[A\u001B[A\n",
      "\n",
      " 69%|██████▊   | 90/131 [00:48<00:21,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 69%|██████▉   | 91/131 [00:48<00:21,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 70%|███████   | 92/131 [00:49<00:20,  1.94it/s]\u001B[A\u001B[A\n",
      "\n",
      " 71%|███████   | 93/131 [00:49<00:19,  1.92it/s]\u001B[A\u001B[A\n",
      "\n",
      " 72%|███████▏  | 94/131 [00:50<00:19,  1.91it/s]\u001B[A\u001B[A\n",
      "\n",
      " 73%|███████▎  | 95/131 [00:50<00:18,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 73%|███████▎  | 96/131 [00:51<00:18,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 74%|███████▍  | 97/131 [00:51<00:17,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 75%|███████▍  | 98/131 [00:52<00:17,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 76%|███████▌  | 99/131 [00:53<00:17,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 76%|███████▋  | 100/131 [00:53<00:16,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 77%|███████▋  | 101/131 [00:54<00:15,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 78%|███████▊  | 102/131 [00:54<00:15,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 79%|███████▊  | 103/131 [00:55<00:14,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 79%|███████▉  | 104/131 [00:55<00:14,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 80%|████████  | 105/131 [00:56<00:13,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 81%|████████  | 106/131 [00:56<00:13,  1.90it/s]\u001B[A\u001B[A\n",
      "\n",
      " 82%|████████▏ | 107/131 [00:57<00:12,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 82%|████████▏ | 108/131 [00:57<00:12,  1.80it/s]\u001B[A\u001B[A\n",
      "\n",
      " 83%|████████▎ | 109/131 [00:58<00:12,  1.80it/s]\u001B[A\u001B[A\n",
      "\n",
      " 84%|████████▍ | 110/131 [00:59<00:11,  1.81it/s]\u001B[A\u001B[A\n",
      "\n",
      " 85%|████████▍ | 111/131 [00:59<00:10,  1.84it/s]\u001B[A\u001B[A\n",
      "\n",
      " 85%|████████▌ | 112/131 [01:00<00:10,  1.86it/s]\u001B[A\u001B[A\n",
      "\n",
      " 86%|████████▋ | 113/131 [01:00<00:09,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 87%|████████▋ | 114/131 [01:01<00:09,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 88%|████████▊ | 115/131 [01:01<00:08,  1.89it/s]\u001B[A\u001B[A\n",
      "\n",
      " 89%|████████▊ | 116/131 [01:02<00:07,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 89%|████████▉ | 117/131 [01:02<00:07,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 90%|█████████ | 118/131 [01:03<00:07,  1.80it/s]\u001B[A\u001B[A\n",
      "\n",
      " 91%|█████████ | 119/131 [01:03<00:06,  1.80it/s]\u001B[A\u001B[A\n",
      "\n",
      " 92%|█████████▏| 120/131 [01:04<00:06,  1.79it/s]\u001B[A\u001B[A\n",
      "\n",
      " 92%|█████████▏| 121/131 [01:04<00:05,  1.81it/s]\u001B[A\u001B[A\n",
      "\n",
      " 93%|█████████▎| 122/131 [01:05<00:04,  1.82it/s]\u001B[A\u001B[A\n",
      "\n",
      " 94%|█████████▍| 123/131 [01:06<00:04,  1.84it/s]\u001B[A\u001B[A\n",
      "\n",
      " 95%|█████████▍| 124/131 [01:06<00:03,  1.85it/s]\u001B[A\u001B[A\n",
      "\n",
      " 95%|█████████▌| 125/131 [01:07<00:03,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 96%|█████████▌| 126/131 [01:07<00:02,  1.84it/s]\u001B[A\u001B[A\n",
      "\n",
      " 97%|█████████▋| 127/131 [01:08<00:02,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 98%|█████████▊| 128/131 [01:08<00:01,  1.88it/s]\u001B[A\u001B[A\n",
      "\n",
      " 98%|█████████▊| 129/131 [01:09<00:01,  1.87it/s]\u001B[A\u001B[A\n",
      "\n",
      " 99%|█████████▉| 130/131 [01:09<00:00,  1.84it/s]\u001B[A\u001B[A\n",
      "\n",
      "100%|██████████| 131/131 [01:10<00:00,  1.86it/s]\u001B[A\u001B[A\n"
     ]
    },
    {
     "data": {
      "text/plain": "131"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import librosa\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "def process_mp3(path):\n",
    "    signal, sr = librosa.load(path,\n",
    "                              res_type=\"kaiser_fast\",\n",
    "                              offset=30,\n",
    "                              duration=30)\n",
    "    melspec = librosa.feature.melspectrogram(signal, sr=sr).T[:1280, ]\n",
    "    if len(melspec) != 1280:\n",
    "        return None\n",
    "    return {'path': path,\n",
    "            'melspecs': np.asarray(np.split(melspec, 10))}\n",
    "\n",
    "songs = [process_mp3(path) for path in tqdm(mp3s)]\n",
    "songs = [song for song in songs if song]\n",
    "\n",
    "len(songs)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "为对每个 MP3 的所有频谱进行索引，我们可以把他们连在一起，方便一批完成"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "(1310, 128, 128)"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs = []\n",
    "\n",
    "for song in songs:\n",
    "    inputs.extend(song['melspecs'])\n",
    "inputs = np.array(inputs)\n",
    "inputs.shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "用之前分类的那个训练好的模型，"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 14%|█▍        | 19/134 [35:25<3:34:22, 111.85s/it]\n",
      " 97%|█████████▋| 130/134 [33:40<01:02, 15.54s/it]\n",
      "2022-01-07 16:02:15.591252: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA\n",
      "To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"model_6\"\n",
      "_________________________________________________________________\n",
      " Layer (type)                Output Shape              Param #   \n",
      "=================================================================\n",
      " input_7 (InputLayer)        [(None, 128, 128)]        0         \n",
      "                                                                 \n",
      " conv1d_18 (Conv1D)          (None, 126, 64)           24640     \n",
      "                                                                 \n",
      " batch_normalization_18 (Bat  (None, 126, 64)          256       \n",
      " chNormalization)                                                \n",
      "                                                                 \n",
      " max_pooling1d_18 (MaxPoolin  (None, 63, 64)           0         \n",
      " g1D)                                                            \n",
      "                                                                 \n",
      " conv1d_19 (Conv1D)          (None, 61, 128)           24704     \n",
      "                                                                 \n",
      " batch_normalization_19 (Bat  (None, 61, 128)          512       \n",
      " chNormalization)                                                \n",
      "                                                                 \n",
      " max_pooling1d_19 (MaxPoolin  (None, 30, 128)          0         \n",
      " g1D)                                                            \n",
      "                                                                 \n",
      " conv1d_20 (Conv1D)          (None, 28, 256)           98560     \n",
      "                                                                 \n",
      " batch_normalization_20 (Bat  (None, 28, 256)          1024      \n",
      " chNormalization)                                                \n",
      "                                                                 \n",
      " max_pooling1d_20 (MaxPoolin  (None, 14, 256)          0         \n",
      " g1D)                                                            \n",
      "                                                                 \n",
      " global_max_pooling1d_6 (Glo  (None, 256)              0         \n",
      " balMaxPooling1D)                                                \n",
      "                                                                 \n",
      " dense_18 (Dense)            (None, 256)               65792     \n",
      "                                                                 \n",
      " dropout_12 (Dropout)        (None, 256)               0         \n",
      "                                                                 \n",
      " dense_19 (Dense)            (None, 256)               65792     \n",
      "                                                                 \n",
      " dropout_13 (Dropout)        (None, 256)               0         \n",
      "                                                                 \n",
      " dense_20 (Dense)            (None, 10)                2570      \n",
      "                                                                 \n",
      "=================================================================\n",
      "Total params: 283,850\n",
      "Trainable params: 282,954\n",
      "Non-trainable params: 896\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "from tensorflow.keras.models import load_model\n",
    "\n",
    "cnn_model = load_model('./song_classify.h5')\n",
    "cnn_model.summary()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "不要最后4层："
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [],
   "source": [
    "from tensorflow.keras import Model\n",
    "\n",
    "vectorize_model = Model(inputs=cnn_model.input,\n",
    "                        outputs=cnn_model.layers[-4].output)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "把 inputs 送进去，跑出来一个歌曲(片段)的 256 维表示向量。"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "data": {
      "text/plain": "(1310, 256)"
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vectors = vectorize_model.predict(inputs)\n",
    "vectors.shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "然后用一个最近邻模型就可以找出相似的歌曲："
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "\n",
    "from sklearn.neighbors import NearestNeighbors\n",
    "\n",
    "nbrs = NearestNeighbors(n_neighbors=10, algorithm='ball_tree').fit(vectors)\n",
    "\n",
    "def most_similar_songs(song_idx):\n",
    "    distances, indices = nbrs.kneighbors(\n",
    "        vectors[song_idx * 10: song_idx * 10 + 10])\n",
    "    c = Counter()\n",
    "    for row in indices:\n",
    "        for idx in row[1:]:\n",
    "            c[idx // 10] += 1\n",
    "    return c.most_common()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "随便指定首歌试一下："
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "source": [
    "def song_name(song_idx):\n",
    "    return os.path.basename(songs[song_idx]['path'])\n",
    "\n",
    "def print_similar_songs(song_idx, start=1, end=6):\n",
    "    print(\"指定歌曲:\", song_name(song_idx))\n",
    "    # 跳过第一相似的：本身\n",
    "    for idx, score in most_similar_songs(song_idx)[start:end]:\n",
    "        print(f\"[相似度{score}] {song_name(idx)}\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 46,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "把曲目列出来方便找："
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 Evan Call - A Place to Call Home.mp3\n",
      "1 Eminem - Remind Me.mp3\n",
      "2 EB - 来一发.mp3\n",
      "3 岸部眞明 - 暗の中で.mp3\n",
      "4 EB - 活着.mp3\n",
      "5 宇多田ヒカル - One Last Kiss (Instrumental).mp3\n",
      "6 Eminem／Skylar Grey - Tragic Endings.mp3\n",
      "7 Beyond - Amani.mp3\n",
      "8 Returning Home.mp3\n",
      "9 孙燕姿 - 遇见.mp3\n",
      "10 Eagles - Hotel California.mp3\n",
      "11 Scarborough Fair - Scarborough Fair.mp3\n",
      "12 04 Longshuo Melody.mp3\n",
      "13 Eminem／Alicia Keys - Like Home.mp3\n",
      "14 岑宁儿 - 追光者.mp3\n",
      "15 黑豹乐队 - 无地自容.mp3\n",
      "16 宇多田ヒカル - One Last Kiss.mp3\n",
      "17 宇多田ヒカル - Beautiful World (Da Capo Version) (Instrumental).mp3\n",
      "18 岸部眞明 - 云の海.mp3\n",
      "19 EB - 杀死差不多先生.mp3\n",
      "20 Evan Call - A Bit of Sass.mp3\n",
      "21 Claude Debussy - Reverie.mp3\n",
      "22 岸部眞明 - 里山の夏.mp3\n",
      "23 EB - F...,Love.mp3\n",
      "24 Eminem - Castle.mp3\n",
      "25 Bryan Adans - Everything I Do For You.mp3\n",
      "26 Beyond - 喜欢你.mp3\n",
      "27 Claudio Arrau - Waltz No. 10 in B minor, op. 69 no. 2.mp3\n",
      "28 梁静茹 - 爱久见人心.mp3\n",
      "29 Antonio Vivaldi - L'Estro Armonico No. 9 in D Major II. Larghetto.mp3\n",
      "30 Lioned Richie - Say You Say Me.mp3\n",
      "31 Eminem／Beyoncé - Walk On Water.mp3\n",
      "32 I Just Call To Say I Love You - I Just Call To Say I Love You.mp3\n",
      "33 Beyond - 灰色轨迹.mp3\n",
      "34 宇多田ヒカル - 桜流し -2021 Remastered-.mp3\n",
      "35 Eminem - Believe.mp3\n",
      "36 Evan Call - One Last Message.mp3\n",
      "37 陈粒 - 走马.mp3\n",
      "38 09 Wen Wang's Melody.mp3\n",
      "39 02 Melody of Contemplation.mp3\n",
      "40 蔡琴 - 渡口.mp3\n",
      "41 Evan Call - An Admirable Doll.mp3\n",
      "42 林俊杰 - 江南.mp3\n",
      "43 Righteous Brothers - Unchained Melody.mp3\n",
      "44 Evan Call - Each Memory a Message.mp3\n",
      "45 齐秦 - 不让我的眼泪陪我过夜.mp3\n",
      "46 06 Three Departures for Yangguan.mp3\n",
      "47 岸部眞明 - 树氷の辉き.mp3\n",
      "48 EB - 选择.mp3\n",
      "49 岸部眞明 - 时を超えて.mp3\n",
      "50 Evan Call - Theme of Violet Evergarden.mp3\n",
      "51 Michael Bolton - When A Man Love A Woman.mp3\n",
      "52 大鹏 - 都选C.mp3\n",
      "53 岸部眞明 - 山顶夕景.mp3\n",
      "54 All Out Love Air Supply - All Out Love Air Supply.mp3\n",
      "55 Evan Call - Back in Business.mp3\n",
      "56 岸部眞明 - Morning glory.mp3\n",
      "57 Evan Call - A Simple Mission.mp3\n",
      "58 03 Beautiful Evening Prelude.mp3\n",
      "59 陈粒 - 小半.mp3\n",
      "60 EB - 世界是你的.mp3\n",
      "61 岸部眞明 - 遥かなる富士.mp3\n",
      "62 贝多芬 - 致艾丽丝.mp3\n",
      "63 岸部眞明 - 奇迹の山.mp3\n",
      "64 尤大淳 - 土耳其进行曲.mp3\n",
      "65 贝多芬 - Adagio Cantabile from Sonata Op.13 (Pathetique).mp3\n",
      "66 宇多田ヒカル - Beautiful World (Da Capo Version).mp3\n",
      "67 Eminem - Arose.mp3\n",
      "68 BeritrHiggins - Casablanca.mp3\n",
      "69 齐秦 - 大约在冬季.mp3\n",
      "70 岸部眞明 - 春、来る.mp3\n",
      "71 Evan Call - A Doll's Beginning.mp3\n",
      "72 宇多田ヒカル - Beautiful World -2021 Remastered-.mp3\n",
      "73 Gong-Liang Cheng  - Drowning Sorrows.mp3\n",
      "74 Evan Call - The Voice in My Heart.mp3\n",
      "75 Beyond - 不再犹豫.mp3\n",
      "76 Evan Call - Unspoken Words.mp3\n",
      "77 Evan Call - Those Words You Spoke to Me.mp3\n",
      "78 Evan Call - Violet Snow for Orchestra.mp3\n",
      "79 岸部眞明 - 流れ行く云.mp3\n",
      "80 岸部眞明 - 幻想の森.mp3\n",
      "81 宇多田ヒカル - Beautiful World (PLANiTb Acoustica Mix) -2021 Remastered-.mp3\n",
      "82 Evan Call - Strangeling.mp3\n",
      "83 07 Changmen Lament.mp3\n",
      "84 Evan Call - Rust.mp3\n",
      "85 Artur Rubinstein／Chopin - Nocturne No. 2 in E Flat Major, Op. 9, No. 2.mp3\n",
      "86 Evan Call - Another Sunny Day.mp3\n",
      "87 贝多芬 - Symphony No. 9 in D minor.mp3\n",
      "88 Eminem - Framed.mp3\n",
      "89 ShakinStelens - Because I Love You.mp3\n",
      "90 唐磊 - 丁香花.mp3\n",
      "91 零点 - 爱不爱我.mp3\n",
      "92 Eminem／P!nk - Need Me.mp3\n",
      "93 Eminem - Heat.mp3\n",
      "94 Evan Call - To The Ends of Our World.mp3\n",
      "95 Richanel Max - Righte Here waiting.mp3\n",
      "96 亨德尔 - Serse, Largo.mp3\n",
      "97 Eminem／X Ambassadors - Bad Husband.mp3\n",
      "98 岸部眞明 - 风、走る(piano solo).mp3\n",
      "99 Carpenters - Yesterday Once More.mp3\n",
      "100 Brian Crain - canon in d.mp3\n",
      "101 齐秦 - 往事随风.mp3\n",
      "102 Whan - CareLess Whisper.mp3\n",
      "103 Eminem／PHRESHER - Chloraseptic.mp3\n",
      "104 苏打绿 - 小情歌.mp3\n",
      "105 EB - 你好.mp3\n",
      "106 Celine Dion - My Heart Will go on.mp3\n",
      "107 亨德尔 - Xerxes, HWV 40- Largo (''Ombra mai fu'').mp3\n",
      "108 Whitne Houstone - I Will Always Love You.mp3\n",
      "109 Eminem／Kehlani - Nowhere Fast.mp3\n",
      "110 Eminem - Untouchable.mp3\n",
      "111 Evan Call - The Birth of a Legend.mp3\n",
      "112 EB - 星夜.mp3\n",
      "113 Evan Call - In Remembrance.mp3\n",
      "114 齐秦 - 夜夜夜夜.mp3\n",
      "115 EB - 再见.mp3\n",
      "116 EB - 微光.mp3\n",
      "117 EB - 死灰.mp3\n",
      "118 Evan Call - The Long Night.mp3\n",
      "119 林俊杰／蔡卓妍 - 小酒窝.mp3\n",
      "120 Phil Collins - Anotherday In Paradise .mp3\n",
      "121 EB - 你挡不住我.mp3\n",
      "122 逃跑计划 - 夜空中最亮的星.mp3\n",
      "123 Evan Call - Ink to Paper.mp3\n",
      "124 05 The Sun.mp3\n",
      "125 宇多田ヒカル - Fly Me To The Moon (In Other Worlds) (2007 Mix) -2021 Remastered-.mp3\n",
      "126 Eminem／Ed Sheeran - River.mp3\n",
      "127 弗朗茨·李斯特／Leslie Howard - Franz Liszt： Hungarian Rhapsodies S.244 - No.11 in A minor ／ F sharp major： Rapsodie hongroise XI.mp3\n",
      "128 Eminem - Offended.mp3\n",
      "129 岸部眞明 - 风、走る.mp3\n",
      "130 Eminem - In Your Head.mp3\n"
     ]
    }
   ],
   "source": [
    "for s in range(len(songs)):\n",
    "    print(f'{s} {song_name(s)}')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: 宇多田ヒカル - Beautiful World (Da Capo Version) (Instrumental).mp3\n",
      "[相似度27] 宇多田ヒカル - Beautiful World (Da Capo Version).mp3\n",
      "[相似度24] 宇多田ヒカル - Beautiful World (Da Capo Version) (Instrumental).mp3\n",
      "[相似度6] Evan Call - Each Memory a Message.mp3\n",
      "[相似度4] Evan Call - One Last Message.mp3\n",
      "[相似度4] Richanel Max - Righte Here waiting.mp3\n",
      "[相似度3] Evan Call - The Voice in My Heart.mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(17, start=0)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "从 Instrumental 找到了有唱的版本。"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: Evan Call - Theme of Violet Evergarden.mp3\n",
      "[相似度6] 齐秦 - 往事随风.mp3\n",
      "[相似度5] Evan Call - An Admirable Doll.mp3\n",
      "[相似度5] Evan Call - Ink to Paper.mp3\n",
      "[相似度4] Evan Call - Rust.mp3\n",
      "[相似度4] 贝多芬 - 致艾丽丝.mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(50)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "混入了奇怪的东西。"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: 贝多芬 - Adagio Cantabile from Sonata Op.13 (Pathetique).mp3\n",
      "[相似度10] Antonio Vivaldi - L'Estro Armonico No. 9 in D Major II. Larghetto.mp3\n",
      "[相似度9] 贝多芬 - Adagio Cantabile from Sonata Op.13 (Pathetique).mp3\n",
      "[相似度8] 贝多芬 - Symphony No. 9 in D minor.mp3\n",
      "[相似度7] 贝多芬 - 致艾丽丝.mp3\n",
      "[相似度7] Claudio Arrau - Waltz No. 10 in B minor, op. 69 no. 2.mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(65)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "古典音乐找的非常好。"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: 岸部眞明 - 流れ行く云.mp3\n",
      "[相似度12] 岸部眞明 - 流れ行く云.mp3\n",
      "[相似度12] 岸部眞明 - 遥かなる富士.mp3\n",
      "[相似度10] 岸部眞明 - 奇迹の山.mp3\n",
      "[相似度6] 岸部眞明 - 云の海.mp3\n",
      "[相似度6] 岸部眞明 - 里山の夏.mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(79)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "指弹也能很好分辨"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: 03 Beautiful Evening Prelude.mp3\n",
      "[相似度7] 06 Three Departures for Yangguan.mp3\n",
      "[相似度7] Gong-Liang Cheng  - Drowning Sorrows.mp3\n",
      "[相似度7] Evan Call - Rust.mp3\n",
      "[相似度5] 03 Beautiful Evening Prelude.mp3\n",
      "[相似度4] Evan Call - The Voice in My Heart.mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(58)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "古琴也还好，但混了两首薇就很离谱，两首都是提琴，跟古琴哪像了。"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: Eminem - Offended.mp3\n",
      "[相似度9] EB - 世界是你的.mp3\n",
      "[相似度7] EB - 来一发.mp3\n",
      "[相似度6] Beyond - 喜欢你.mp3\n",
      "[相似度5] Eminem／Beyoncé - Walk On Water.mp3\n",
      "[相似度4] 宇多田ヒカル - One Last Kiss (Instrumental).mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(128)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "HipHop 也还行，可以跨越语种的找到，但会混一些其他的进去。"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: Beyond - 灰色轨迹.mp3\n",
      "[相似度12] 齐秦 - 往事随风.mp3\n",
      "[相似度10] Beyond - 灰色轨迹.mp3\n",
      "[相似度8] Whan - CareLess Whisper.mp3\n",
      "[相似度8] All Out Love Air Supply - All Out Love Air Supply.mp3\n",
      "[相似度4] BeritrHiggins - Casablanca.mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(33)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "流行也还行。"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "指定歌曲: Beyond - 不再犹豫.mp3\n",
      "[相似度8] Eminem - Untouchable.mp3\n",
      "[相似度7] Beyond - 不再犹豫.mp3\n",
      "[相似度6] EB - 你挡不住我.mp3\n",
      "[相似度6] I Just Call To Say I Love You - I Just Call To Say I Love You.mp3\n",
      "[相似度5] Eminem／Skylar Grey - Tragic Endings.mp3\n",
      "[相似度5] Carpenters - Yesterday Once More.mp3\n"
     ]
    }
   ],
   "source": [
    "print_similar_songs(75, start=0)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "这个摇滚就不太好了，前面做分类摇滚也是分的很迷，这个模型就不太喜欢听摇滚吧。"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}